package 校赛.真题._2022校赛;

import java.util.Scanner;

/**
 * @author 挚爱之夕
 * @version 1.0
 * @implSpec 校赛.真题._2022校赛
 * @since 2023 - 03 - 27 - 20:08
 */
public class D_BUFF {
}
class Main_D{
    static int l = 200010;
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), t = sc.nextInt();
        int[] buff = new int[l];
        int[] debuff = new int[l];
        int xi, ai;
        for(int i = 0; i < n; i++){
            xi = sc.nextInt();
            ai = sc.nextInt();
            //构造查分数组
            if(xi == 1){
                buff[ai]++;
                buff[ai + t]--;
            }else{
                debuff[ai]++;
                debuff[ai + t]--;
            }
        }
        int res = 0;
        //进行累加，得到buff[i], 为0则没有buff,大于0存在buff
        for(int i = 1; i < l; i++){
            buff[i] += buff[i - 1];
            debuff[i] += debuff[i - 1];
            if(buff[i] > 0 && debuff[i] == 0){
                res++;
            }
        }
        System.out.println(res);
    }
}
